package com.mdnote.practice.hash;

import com.mdnote.practice.linked_list.LeetCode25;
import jdk.internal.org.objectweb.asm.tree.MultiANewArrayInsnNode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author Rhythm-2019
 * @version 1.0
 * @date 2020/10/14 0014
 * @description
 */
public class LeetCode1002 {


    public static void main(String[] args) {
        LeetCode1002 leetCode1002 = new LeetCode1002();
        List<String> strings = leetCode1002.commonChars(new String[]{"abckkkk", "abc", "abc"});
        System.out.println(strings);
    }
    public List<String> commonChars(String[] A) {

        int[] counter = new int[26];
        Arrays.fill(counter, Integer.MAX_VALUE);

        for (String s : A) {

            int[] freq = new int[26];
            for (int i = 0; i < s.length(); i++) {
                freq[s.charAt(i) - 'a']++;
            }

            for (int i = 0; i < 26; i++) {
                counter[i] = Math.min(counter[i], freq[i]);
            }
        }

        List<String> resList = new ArrayList<>();
        for (int i = 0; i < 26; i++) {
            for (int j = 0; j < counter[i]; j++) {
                resList.add(new String((char)(i + 'a') + ""));
            }
        }

        return resList;
    }




}
